// pages/to_consult/consult/index.js
// pages/department/info/index.js
const httpUtils = require('../../../utils/httpUtils')
const ui = require('../../../utils/ui')
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs: ['健康科普', '线上问诊', '预约挂号'],
        doctor: {},
        department: {},
        showIndex: 0
    },

    checkboxChange(e) {
        console.log(e)
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let id = options.doctorId
        this.getDoctorById(id)
    },

    getDoctorById(id) {
        var _this = this
        //发送请求
        httpUtils.request({
            method: "GET",
            showLoading: true,
            url: `/api/doctor/` + id,
            message: "正在获取...",
            data: _this.data.page,
        }).then(res => {
            if (res.data.code != 0) {
                ui.showToast(res.data.mes)
            } else {
                res.data.data.info = JSON.parse(res.data.data.introduce)
                let duties = res.data.data.info.duties.split('、')
                res.data.data.info.duties = duties

                _this.setData({
                    doctor: res.data.data
                })

                console.log(_this.data.doctor)
                _this.getDepartmentById(_this.data.doctor.department_id)
            }
        }).catch(err => {
            console.log(err)
        });
    },
    getDepartmentById(id) {
        var _this = this
        //发送请求
        httpUtils.request({
            method: "GET",
            showLoading: true,
            url: `/api/department/` + id,
            message: "正在获取...",
            data: _this.data.page,
        }).then(res => {
            if (res.data.code != 0) {
                ui.showToast(res.data.mes)
            } else {
                _this.setData({
                    department: res.data.data
                })
            }
        }).catch(err => {
            console.log(err)
        });
    },
    change(e) {
        this.setData({
            showIndex: e.detail.index
        })
        console.log(this.data.showIndex)
    },
    apply() {
        let _this = this
        wx.navigateTo({
            url: '../apply/index?doctorId=' + _this.data.doctor.id,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})